<table width="778" cellspacing="0" cellpadding="0" border="0"><tbody>
<tr><td width="778" valign="bottom" align="right" class="catHmBar"  height="52">
<div class="classtype"><?php 
 //查找下级栏目
    $parent_id= $current_category_id;
	$categories_query = "select c.categories_id, cd.categories_name,c.categories_type
             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
             where parent_id = '" . (int)$parent_id . "'
             and c.categories_id = cd.categories_id
             and c.categories_status=1
             and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
             order by sort_order, cd.categories_name";

$categories = $db->Execute($categories_query);
$category_type_array=array('b'=>0,'s'=>0,'m'=>0,'p'=>0);
$categories_array=array();
while (!$categories->EOF) {
  if($categories->fields['categories_type']!=''){
      foreach ($category_type_array as $k=>$v)
      {
      	if($k==$categories->fields['categories_type'])
      	{
      		$category_type_array[$k]++;
      	} 	
      }
  }
  $categories_array[]=array('id'=>$categories->fields['categories_id'],
                             'name'=>$categories->fields['categories_name'])
                             ;
  $categories->MoveNext();
}
$max_key=array_search(max($category_type_array),$category_type_array);
if($category_type_array[$max_key]==0){
	  //栏目下的所有 子类都没有定义 栏目类型 
	  $dataProductType="Product SubCategoryType";
}elseif($max_key=='b'){
	  $dataProductType="Product Brand";
}elseif($max_key=='s'){
	  $dataProductType="Product Series";
}elseif($max_key=='m'){
	  $dataProductType="Product Model";
}elseif($max_key=='p'){
	  $dataProductType="Product Type"; 	
}else{
	  $dataProductType="Product SubCategoryType";
}
echo $dataProductType;
?></div>
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr>
<?php for($i=0;$i<6;$i++){
	if($i>=count($categories_array)){break;}
	?>
<td align="top" style="padding-left: 3px; padding-top: 8px;" class="catetypelink">
<a href="javascript:void(0);" <?php if($i==0){ echo 'class="current"';} ?> onclick="ShowCate(<?php echo $categories_array[$i]['id']; ?>);"  id="cate<?php echo $categories_array[$i]['id']; ?>"><?php echo $categories_array[$i]['name']; ?></a>
</td>
<?php }?>
<td align="top" style="padding-left: 3px; padding-top: 8px;">
<img border="0" onclick="self.location.href='<?php echo HTTP_SERVER.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&listtype=all' ?>';" style="border: 0px none; cursor: pointer; display: block;" src="<?php echo DIR_WS_TEMPLATE_IMAGES;?>off_all.gif" id="general_up99">
</td>
</tr></tbody></table>


</td></tr>
<tr><td width="778" valign="top" class="catHmBox">
<?php for($i=0;$i<6;$i++){
	if($i>=count($categories_array)){break;}
	?>
<div style="<?php if($i!=0){ echo 'display:none';} ?>" id="general_div<?php echo $categories_array[$i]['id']; ?>">
  <table height="205" cellspacing="0" cellpadding="0" border="0">
    <tbody>
      <tr>
<?php

 if (isset($categories_array[$i]['id']) && ($categories_array[$i]['id'] > 0)) {
 	   	 //查找下级栏目
   	   	    $parent_id= $categories_array[$i]['id'];
	   	   	$categories_query = "select c.categories_id, cd.categories_name,c.categories_type,c.categories_image,cd.categories_description
	                         from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
	                         where parent_id = '" . (int)$parent_id . "'
	                         and c.categories_id = cd.categories_id
	                         and c.categories_status=1
	                         and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
	                         order by sort_order, cd.categories_name";
	
	        $categories = $db->Execute($categories_query);
	if(!$categories->EOF){
				$j=1;
			      while (!$categories->EOF  and $j<6 ) {
			      	if($j!=1){ $class=' class="catHmItem"';}else{$class='';}
			      	
			 echo ' <td valign="top" '.$class.'>
			          <div style="padding-bottom: 17px;">
			            <div class="catHmImg">
			 <a href="' . zen_href_link(FILENAME_DEFAULT,'cPath='.  $categories->fields['categories_id']).'">'.zen_image(DIR_WS_IMAGES.$categories->fields['categories_image'],140,116).'</a>
			            </div>
			            <div class="catHmTitle">
			              '.$categories->fields['categories_name'].'
			            </div>
			            <div class="catHmDesc">
			             '.$categories->fields['categories_description'].'
			            </div>
			          </div>
			        </td>';
			        $categories->MoveNext();      
					$j++;
				      }
	}else{
 $categories_product_sql = "select distinct p.products_id, pd.products_name, p.products_ordered,p.products_image,pd.products_description
                             from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, "
                                    . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c
                             where p.products_status = '1'
                             and p.products_id = pd.products_id
                             and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                             and p.products_id = p2c.products_id
                             and p2c.categories_id = c.categories_id
                             and '" . (int)$categories_array[$i]['id'] . "' in (c.categories_id, c.parent_id)
                             order by p.products_sort_order, pd.products_name
                             limit 5";

      $cate_product = $db->Execute( $categories_product_sql);
      
$j=1;
      while (!$cate_product->EOF ) {
      	if($j!=1){ $class=' class="catHmItem"';}else{$class='';}
 echo ' <td valign="top" '.$class.'>
          <div style="padding-bottom: 17px;">
            <div class="catHmImg">
 <a href="' . zen_href_link(zen_get_info_page($cate_product->fields['products_id']), 'products_id=' . $cate_product->fields['products_id']) . '">'.zen_get_products_image($cate_product->fields['products_id'],140,116).'</a>
            </div>
            <div class="catHmTitle">
              '.$cate_product->fields['products_name'].'
            </div>
            <div class="catHmDesc">
             '.$cate_product->fields['products_description'].'
            </div>
          </div>
        </td>';  
        $cate_product->MoveNext();    
		$j++;
	      }     
	}
 }
?>
      </tr>
    </tbody>
  </table>
</div>
<?php }?>
</td></tr>
<tr><td><?php echo zen_image(DIR_WS_TEMPLATE_IMAGES . 'comm_bottom.gif'); ?></td></tr>
</tbody></table>
